import Vue from 'vue';
import Router from 'vue-router';
import Layout from '@/views/layout/Layout';
import { constantRouterMap, asyncRouterMap } from './routerMap';

/* eslint import/no-dynamic-require: "off" */
// in development-env not use lazy-loading, because lazy-loading too many pages will cause
// webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router);

const constantMap = constantRouterMap.map((item) => {
  if (item.component === 'Layout') {
    item.component = Layout;
  }
  return item;
});

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap,
});

const asyncMap = asyncRouterMap.map((item) => {
  if (item.component === 'Layout') {
    item.component = Layout;
  }
  return item;
});

export {
  constantMap,
  asyncMap,
};
